package com.wpq.game_company;

import com.wpq.game_company.domain.Game;
import com.wpq.game_company.domain.User;
import com.wpq.game_company.mapper.GameMapper;
import com.wpq.game_company.service.IGameService;
import com.wpq.game_company.service.IUserService;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.io.IOException;
import java.io.InputStream;

public class testmybatis {

    //1.获取核心容器对象
    ApplicationContext an = new ClassPathXmlApplicationContext("applicationContext.xml");
    //2.根据id获取bean对象
    //在service的实现类中使用了@Service注解，自动创建了bean对象，无需在配置文件中创建bean
    IGameService serviceAn = an.getBean("gameServiceImpl", IGameService.class);
    IUserService serviceUr = an.getBean("userServiceImpl",IUserService.class);

    @Test
    public void testInsertGame(){

        Game game=new Game();
        game.setId(11);
        game.setName("lll");
        game.setType("jakk");
        game.setCompanyId(4);
        serviceAn.insert(game);

    }

    @Test
    public void testSelectAll(){

        System.out.println(serviceAn.selectAll());
    }

    @Test
    public void testeDelete(){
        serviceAn.delete(11);
        System.out.println(serviceAn.selectAll());
    }

    @Test
    public void testeUpdate(){

        Game game=new Game();
        game.setId(11);
        game.setName("222");
        game.setType("111");
        game.setCompanyId(1);
        serviceAn.updata(game);
        System.out.println(serviceAn.selectAll());
    }

    @Test
    public void testInsertUser(){
        User user=new User();
        user.setUid(2);
        user.setUsername("xiaolong");
        user.setPassword("1546");
        user.setEmail("jans@61");
        user.setPhone("15245674589");
        serviceUr.reg(user);



    }
}
